#include "FancyText.h"
#include "Transformation.h"
#include "GameObject.h"
#include "GLTextureFont2D.h"
#include "Camera.h"
#include "TextureManager.h"
#include "Point.h"
#include "Exception.h"

using namespace game_engine;
using namespace game_engine::components;
using namespace game_engine::open_gl;
using namespace game_engine::utils;

///////////////////////////////////////////////////////////////////////////////
// Constructors and Destructors
///////////////////////////////////////////////////////////////////////////////

FancyText::FancyText(void)
    : Component(), textureFile(), textureType()
{
    type = "FancyText";
}

FancyText::FancyText(GameObject *obj, const string &file, const INT32 t)
    : Component(obj), textureFile(file), textureType(t)
{
    type = "FancyText";
}

FancyText::~FancyText(void)
{
}

///////////////////////////////////////////////////////////////////////////////
// Other public methods
///////////////////////////////////////////////////////////////////////////////

void FancyText::initialize(void) throw(...)
{
    TextureManager *tm = TextureManager::getInstance();
    tm->setFont(textureFile, textureType, 16, 16, 16, 16, 10, 0);    
}

void FancyText::render(void) throw(...)
{
    // Retrive the Transformation component
    Transformation *transf;
    try
    {
        transf = dynamic_cast<Transformation*> 
            (object->getComponent("Transformation"));
    } catch (...)
    {
        string msg("[FancyText::render] transformation component not found");
        throw RuntimeException(msg);
    }

    // Calculate offset according to camera position
    Point offset = computeCameraOffset();

    // Draw string at object's position
    TextureManager *tm = TextureManager::getInstance();
    GLTextureFont2D font = tm->getFont(textureFile);
    Point drawPoint(offset.getX() + transf->getXPosition(),
        offset.getY() + transf->getYPosition());
    font.drawString(drawPoint, "hello");
}

///////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////

